<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. zYfkFL
 */

//define('Customer', '0');
//define('Hebrew', '2');
//define('English', '1');

class sbValues {

    const MAIL_SUPPORT_TROLI = 'sivis@sarma.co.il';
    //PERMISSIONS
    const USER_IS_GUEST = -10;
    const PERMISSIONS_STANDART = 1;
    const PERMISSIONS_AGENT = 2;
    const PERMISSIONS_FIRM = 3;
    const PERMISSIONS_ADMIN = 4;
    //TYPE USERS IN STIRNG
    const TYPE_USER_STANDART = "user";
    const TYPE_USER_AGENT = "agent";
    const TYPE_USER_FIRM = "firm";
    const TYPE_USER_ADMIN = "admin";
    //USER STATUS
    const STATUS_ACTIVE = 1;
    const STATUS_DEACTIVE = 2;
    //COUNTRY 
    const COUNTRY_ISRAEL = 1;
    const COUNTRY_RUSSIA = 2;
    //LANGUAGE
    const LANGUAGE_ENGLISH = 1;
    const LANGUAGE_HEBREW = 2;
    const LANGUAGE_RUSSIAN = 3;
    //RESET PASSWORD
    const PASSWORT_RESET_SUCCSESS = 1;
    const PASSWORD_RESED_UNSUCCSESS = 2;
    //PRIORITY
    const PRIORITY_VERY_SMALL = 10;
    const PRIORITY_SMALL = 20;
    const PRIORITY_NORMAL = 30;
    const PRIORITY_HIGH = 40;
    const PRIORITY_VERY_HIGH = 50;
    //URI
//    const URL_LOCALHOST = 'http://localhost/travis/web/uploads/';
//    const URL_SERVER = 'http://localhost/travis/web/backend_dev.php/';
    const URL_LOCALHOST = '/web/uploads/';
    const URL_SERVER = '/web/backend_dev.php/';
    //MAIN USER 
    const MAIN_USER = 3;
    const MAIN_FIRM_USER = 3;
    //SORT HOTELS
    const SORT_BY_RANK = 'rank';
    const SORT_BY_PRICE = 'price';
    const SORT_BY_NAME = 'name';
    //PAGE
    const HOTELS_IN_PAGE = 5;
    const HOTELS_IN_ADMIN_PAGE = 30;
    //PROVIDER
    const PROVIDER_GOC = 1;
    const PROVIDER_ISR = 2;
    const PROVIDER_DAN = 3;
    //USER TYPE
    const USER_TOURIST = 1;
    const USER_ISRAELI = 2;
    //URL PROVIDERS 
    const URL_USD_ISRATEL = 'https://travis-usd.isrotel-services.com/agentsservice.asmx?wsdl';
    const URL_NIS_ISRATEL = 'https://travis.isrotel-services.com/agentsservice.asmx?wsdl';
    const URL_TEST_ISRATEL = 'http://test.isrotel-services.com/agentsservice.asmx?wsdl';
    const URL_TEST_GOC = "http://webbnb.com/SilverAPI.asmx?wsdl";
    const URL_GOC_USD = 'https://secure.webbnb.com/SilverAPI.asmx?wsdl';
    const URL_DAN = 'http://62.0.41.204:8080/agents/agentsService';
    //CITIZENSHIP
    const TOURIST = 1;
    const CIVIC = 2;
    //PAYLOADS METHOD
    const PAYLOADS_PAYPAL = 1;
    const PAYLOADS_CREDIT_CARD = 2;
    const PAYLOADS_BY_PHONE = 3;
    const PAYLOADS_BY_BALANCE = 4;
    const PAYLOADS_BY_AGEND = 5;
    //SORT ORDERS
    const ORDER_SORT_TODAY = 1;
    const ORDER_SORT_MONTH = 2;
    const ORDER_SORT_DATE = 3;
    const ORDER_SORT_ID = 4;
    //ORDERS STATUS 
    const ORDER_STATUS_SUCCESS = 1;
    const ORDER_STATUS_CANCEL = 2;
    const ORDER_STATUS_PROCCESS = 3;
    //DAYS 
    const ALL_DAYS = 'all_days';
    const WORKING_DAYS = 'working_days';
    const WEKEEND = 'weekend';
    //SITE LANGUAGE
    const ENGLISH = 'en';
    const RUSSIAN = 'ru';
    const HEBREW = 'he';
    //DOLLAR RATE
    const DOLLAR_NDS = 0.18;
    const DOLLAR_CORRECT = 0.02;

    //return current time in timestamp
    static public function getCurrentTime() {
        $dateTime = new DateTime(date('r', time()));
        $new = date_timezone_set($dateTime, timezone_open('Asia/Jerusalem'));
        return date_format($new, 'Y-m-d H:i:s');
    }

    //return current time in timestamp
    static public function getCurrentDate() {
        $dateTime = new DateTime(date('r', time()));
        $new = date_timezone_set($dateTime, timezone_open('Asia/Jerusalem'));
        return date_format($new, 'd/m/Y');
    }

    static public function getDateToDB() {
        $dateTime = new DateTime(date('r', time()));
        $new = date_timezone_set($dateTime, timezone_open('Asia/Jerusalem'));
        return date_format($new, 'Y-m-d');
    }

    static public function generatePassword() {
        $arr = array('a', 'b', 'c', 'd', 'e', 'f',
            'g', 'h', 'i', 'j', 'k', 'l',
            'm', 'n', 'o', 'p', 'r', 's',
            't', 'u', 'v', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F',
            'G', 'H', 'I', 'J', 'K', 'L',
            'M', 'N', 'O', 'P', 'R', 'S',
            'T', 'U', 'V', 'X', 'Y', 'Z',
            '1', '2', '3', '4', '5', '6',
            '7', '8', '9', '0');

        $pass = "";

        for ($i = 0; $i < 6; $i++) {
            $index = rand(0, count($arr) - 1);
            $pass .= $arr[$index];
        }

        return $pass;
    }

    static public function createNewEmailToAgent($to, $subject, $message, $headers = null) {
        if ($headers) {
            $header = $headers;
        } else {
            $header = 'From: troli@travis.co.il' . "\r\n" .
                    'To: ' . $to . "\r\n".
                    'Reply-To: ' . $to . "\r\n" .
                    'X-Mailer: PHP/' . phpversion() .
                    'MIME-Version: 1.0' . "\r\n" .
                    'Content-Type: text/html; charset=UTF-8' . "\r\n";
        }

        return mail($to, $subject, $message, $header);
    }

    static public function createNewResetEmail($to, $pass) {
        $subject = 'Reset password';

        $message = '
<html>
<head>
  <title>Reset Password</title>
</head>
<body>
  <p>Dear send you a new password for your account. We strongly recommend that you change it.</p>
  <table>
    <tr>
      <th>username:</th><th>' . $to . '</th><th>password:</th><th>' . $pass . '</th>
    </tr>
  </table>
</body>
</html>
';

        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        $headers .= 'To: ' . $to . "\r\n";
        $headers .= 'From: Support customers support@troli.co.il' . "\r\n";

        $m = mail($to, $subject, $message, $headers);
    }

    public static function allCity() {
        return Doctrine_Core::getTable('tblCity')->createQuery('a')->execute();
    }
    
    public static function allHotels() {
        return Doctrine_Core::getTable('tblHotel')->createQuery('a')->execute();
    }
    
    public static function allRooms() {
        return Doctrine_Core::getTable('tblRooms')->createQuery('a')->execute();
    }
}
